<template>
  <div>
      <h2>快乐淘宝登录页面</h2>
    <van-form :model="form">
      <van-field name="用户名" label="用户名" placeholder="用户名" v-model="form.name" />
      <van-field type="password" name="密码" label="密码" placeholder="密码" v-model="form.password" />
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit" @click="fn">提交</van-button>
      </div>
    </van-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      form: {
        name: "",
        password: "",
      },
    };
  },
  methods: {
    fn() {
      this.$axios
        .post("http://ceshi5.dishait.cn/admin/login", {
          username: this.form.name,
          password: this.form.password,
        })
        .then((res) => {
          localStorage.token = res.data.data.token;
          this.$router.push({ path: "/" });
        })
        .catch(() => {
          alert("登录状态不对");
        });
    },
  },
};
</script>
<style lang="scss">
    h2{
        color:rgb(176, 171, 226);
        text-align: center;
    }
</style>